package com.lb.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

/**
 * @author: xie fei
 * @date 2020/4/13 14:56
 */
public class JdbcUtils {
    // 数据库地址
    private static String dbUrl = "jdbc:mysql://120.77.241.104:3306/libo?useSSL=false&useUnicode=true&characterEncoding=UTF-8";
    // 用户名
    private static String dbUserName = "root";
    // 密码
    private static String dbPassword = "ROOT_root_1234";
    // 驱动名称
    private static String jdbcName = "com.mysql.jdbc.Driver";

    //获取数据库连接
    public static Connection getCon() throws Exception {
        Class.forName(jdbcName);
        //通过访问数据库的URL获取数据库连接对象
        return DriverManager.getConnection(dbUrl, dbUserName, dbPassword);
    }

    public static void close(Statement stmt, Connection con) throws Exception {
        if (stmt != null) {
            stmt.close();
            if (con != null) {
                con.close();
            }
        }
    }
}